<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://jawr.net/tags" prefix="jwr"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>打印</title>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="Bookmark" href="images/favicon.ico" type="image/x-icon" />
<style type="text">
	#wikibody{margin:1em 2em;padding:.25em;}
	#page,#wikibody.fav-right #favorites{float:right;}
	td{align-text:center}
</style>
<jwr:style src="/bundles/extJs.css" />
<jwr:style src="/bundles/apps.css" />
<jwr:script src="/bundles/extJs.js" />
<jwr:script src="/bundles/common.js" />
<jwr:script src="/bundles/component.js" />
<jwr:script src="/bundles/customize.js" />
<script src="lib/vas/js/jquery-1.4.2.min.js" ></script>
<script src="lib/vas/js/jquery.jPrintArea.js"></script>
<script>
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var year = now.getFullYear();    //获取完整的年份(4位,1970-????)
var month = now.getMonth();       //获取当前月份(0-11,0代表1月)
var day = now.getDate();        //获取当前日(1-31)
var timeValue = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;

function printContent(id){	
	var iframe=document.createElement('IFRAME');
	var doc=null;
	iframe.style='position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
	document.body.appendChild(iframe);
	doc=iframe.contentWindow.document;
	var links=window.document.getElementsByTagName('link');
	for(var i=0;i<links.length;i++)
	if(links[i].rel.toLowerCase()=='stylesheet')
	doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
	doc.write('<div>'+document.getElementById(id).innerHTML+'</div>');
	doc.close();
	iframe.contentWindow.focus();
	iframe.contentWindow.print();
	Ext.Msg.alert('提示','Printing...');
	document.body.removeChild(iframe);
	
}

function getdata(){
Ext.getBody().mask("正在创建数据.请稍等...","x-mask-loading");
Ext.Ajax.request({
		 url:"admin/dcxt/order!printView.action?id="+<%=request.getParameter("id") %>,
		 method : "POST",
         success: function($response){
	     checkTimeOut($response);
	     var responseObj = Ext.util.JSON.decode($response.responseText);
	     if(responseObj.success){
	    	 var len  =  responseObj.data.length;
		     if(len ===0 || len==""){
		    	 Ext.Msg.alert("提示","没有相应的数据");
			     }else{
                  var dishesData  =  responseObj.data;
                  var html = "<p><button onclick='printContent(\"content\")'>打印</button></p><p style='padding-left:80px'>客户小票</p><p>日&nbsp;期： "+timeValue+"</p><p>---------------------------------</p>";
                  html+="<table width=\"300\" border=\"0\">";
                  html+="<tr><td width=\"100\" > 菜 名</td><td width=\"100\">价 格</td>";
                  html+="<td width=\"100\" >份 数</td></tr>";
                  var totalMoeny=0;
                  for(var i = 0; i<len;i++){
                	 var name =   dishesData[i].dishes_name;
                	 totalMoeny+= parseInt(dishesData[i].dishes_price)*parseInt(dishesData[i].count);
                	  html+="<tr><td>"+name+"</td><td>"+dishesData[i].dishes_price+"元</td><td>"+dishesData[i].count+"</td></tr>";
                      }
                  html+="<tr><td colspan=\"3\">---------------------------------</td></tr>";
                  html+="<tr><td colspan=\"3\" align='right'>总计金额: "+totalMoeny+"元</td></tr>";
                    document.getElementById("content").innerHTML=html+"</table>";
			    	 
				     }
		     }else{
		    	 Ext.Msg.alert("提示","获取数据失败");
			     }
	     Ext.getBody().unmask();
    }
})
}
</script>
</head>
<body onload="getdata()">

    <div style="margin-left:50px" id="content"></div>

</body>
</html>
